package com.zhj.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhj.product.converter.ItemsConverter;
import com.zhj.product.entity.dto.GoodItemsDTO;
import com.zhj.product.entity.dto.ItemsDTO;
import com.zhj.product.entity.pojo.Items;
import com.zhj.product.entity.pojo.ItemsImg;
import com.zhj.product.entity.pojo.ItemsParam;
import com.zhj.product.entity.pojo.ItemsSpec;
import com.zhj.product.mapper.ItemsMapper;
import com.zhj.product.service.*;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@AllArgsConstructor
public class ItemsServiceImpl implements ItemsService {

    private final ItemsMapper itemsMapper;

    /**
     * 获取评论
     */
    private final ItemsCommentsService itemsCommentsService;

    /**
     * 获取商品图片
     */
    private final ItemsImgService itemsImgService;

    /**
     * 获取商品的规格
     */
    private final ItemsSpecService itemsSpecService;

    /**
     * 获取到商品的参数
     */
    private final ItemsParamService itemsParamService;

    @Override
    public List<GoodItemsDTO> selectGoodItems(Integer categoryId) {
        return itemsMapper.selectGoodItems(categoryId);
    }

    /**
     * 根据id查询商品详情
     * @param itemId
     * @return
     */
    @Override
    public ItemsDTO selectItemById(String itemId) {
        LambdaQueryWrapper<Items> queryWrapper = new QueryWrapper<Items>().lambda().eq(Items::getId, itemId);
        Items items = itemsMapper.selectOne(queryWrapper);
        List<ItemsImg> itemsImgs = itemsImgService.selectImagesByItemId(itemId);
        List<ItemsSpec> itemsSpecs = itemsSpecService.selectSpecByItemId(itemId);
        ItemsParam itemsParams = itemsParamService.selectParamByItemId(itemId);
        return new ItemsDTO().setItem(items).setItemImgList(itemsImgs).setItemParams(itemsParams).setItemSpecList(itemsSpecs);
    }
}

